/**
 * 数据字典 v1.0
 * @author hebidu 346551990@qq.com
 * @datetime 20170724
 **/
import datatreeApi from '../../api/datatreeApi'
import * as types from '../mutation-types'

// initial state
const state = {
    datatree_result: []
};

// getters
const getters = {
    datatree_result: state => state.datatree_result
};

// actions
const actions = {
    [types.By_Datatree_Query] ({ commit }, queryData) {
        console.debug('[Vuex Action] query data ', queryData);
        commit(types.By_Datatree_Query);
        datatreeApi.query(
            queryData,
            (res) => {
                commit(types.By_Datatree_Query_Done, res);
            },
            (res) => {
                commit(types.By_Datatree_Query_Done, res);
            }
        )
    }
};

// mutations
const mutations = {
    [types.By_Datatree_Query_Done] (state, data) {
        console.debug('By_Datatree_Query_Done', data);
        state.datatree_result = data;
    },
    [types.By_Datatree_Query] (state) {
        console.debug('By_Datatree_Query');
    }
};

export default {
    state,
    getters,
    actions,
    mutations
}